<template>
  <el-dialog id="oth" :title="'账套信息设置'" :close-on-click-modal="false" :visible.sync="visible">
    <!-- 表格 -->
    <div class="day">公司账套银行列表</div>
    <div style="
        background-color: #fff;
        border-radius: 6px;
      ">
      <div style="
          display: flex;
          justify-content: flex-end;
          margin-bottom: 10px;
          box-sizing: border-box;
        "></div>

      <el-table :data="personBankRefs" :header-cell-style="{ background: '#FAFAFA' }" style="width: 100%">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />

          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <el-table-column prop="bankAccountCode" header-align="center" align="center" label="银行账户编码">
        </el-table-column>
        <el-table-column prop="bankAccountName" header-align="center" align="center" label="银行账户名称">
        </el-table-column>
        <el-table-column prop="bankCardCode" header-align="center" align="center" label="银行账号">
        </el-table-column>
        <el-table-column prop="bankOrganizationCode" header-align="center" align="center" label="金融机构编号">
        </el-table-column>
        <el-table-column prop="bankBranchName" header-align="center" align="center" label="金融机构名称">
        </el-table-column>
        <el-table-column prop="bankLineNo" header-align="center" align="center" label="金融机构行名行号">
        </el-table-column>

        <el-table-column fixed="right" header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button v-if="scope.row.isEnable == 1" type="text" size="small" :data-id="scope.row.id" @click="open(scope.row)">停用</el-button>
            <el-button v-if="scope.row.isEnable == 0" type="text" size="small" :data-id="scope.row.id" @click="open(scope.row)">启用</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 表格 -->
    <!-- <div class="day">公司项目列表</div> -->
    <!-- <div style="
        background-color: #fff;

        border-radius: 6px;
      ">
      <div style="
          display: flex;
          justify-content: flex-end;
          margin-bottom: 10px;
          box-sizing: border-box;
        "></div>

      <el-table :data="personProjectRefs" :header-cell-style="{ background: '#FAFAFA' }" style="width: 100%">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />

          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <el-table-column prop="projectCode" header-align="center" align="center" label="项目ID">
        </el-table-column>
        <el-table-column prop="projectName" header-align="center" align="center" label="项目名称">
        </el-table-column>
      </el-table>
    </div> -->
  </el-dialog>
</template>

<script>
export default {
  inject: ["reload"],
  data () {
    return {
      visible: false,
      timeone: "",
      timetwo: "",
      timethree: "",
      status: "",
      personBankRefs: [],
      personProjectRefs: [],
      legalCompanyName: [],
      balanceDateil: {
        legalAccountCode: "",
        legalCompanyName: "",
        bankOrganizationCode: "",
        bankAccountName: "",
        bankCardCode: "",
        bankAccountCode: "",
        bankBranchName: "",
        bankLineNo: "",
        projectName: "",
        projectCode: "",
      },
    };
  },

  methods: {
    init (legalAccountCode) {
      console.log(legalAccountCode);
      this.legalAccountCode = legalAccountCode.legalAccountCode;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/v1/legalPersonDetail/accountDetail"
        ),
        method: "get",
        params: this.$http.adornParams({
          legalAccountCode: legalAccountCode.legalAccountCode,
          legalCompanyName: legalAccountCode.legalCompanyName,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data);
          this.personBankRefs = data.data.personBankRefs;
          this.personProjectRefs = data.data.personProjectRefs;
          // this.balanceDateil.legalAccountCode = data.data.legalAccountCode;
          // this.balanceDateil.legalCompanyName = data.data.legalCompanyName;
          // this.balanceDateil.bankOrganizationCode =
          //   data.data.bankOrganizationCode;
          // this.balanceDateil.bankAccountName = data.data.bankAccountName;
          // this.balanceDateil.bankCardCode = data.data.bankCardCode;
          // this.balanceDateil.bankAccountCode = data.data.bankAccountCode;
          // this.balanceDateil.bankBranchName = data.data.bankBranchName;
          // this.balanceDateil.bankLineNo = data.data.bankLineNo;
          // this.balanceDateil.projectCode = data.data.projectCode;
          // this.balanceDateil.projectName = data.data.projectName;
        } else {
          this.$message.error(data.errorMsg);
        }
      });

      this.visible = true;
    },
    open (e) {
      var that = this;
      var text = "";
      var number = "";
      console.log(e, '2131`2');
      if (e.isEnable == 0) {
        text = "启用";
        number = "1";
      } else {
        text = "停用";
        number = "0";
      }
      this.$confirm("是否" + text, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl(
              "cassadmin/v1/companyAccount/updateEnableStatus"
            ),
            method: "post",
            data: this.$http.adornData({
              bankAccountCode: e.bankAccountCode,
              id: e.id,
              enableType: "bank",
              isEnable: number,
              legalAccountCode: this.legalAccountCode,
            }),
          }).then(({ data }) => {
            if (data.success == 1) {
              this.$message({
                type: "success",
                message: "成功!",
              });
              for (var i = 0; i < this.personBankRefs.length; i++) {
                if (
                  e.bankAccountCode == this.personBankRefs[i].bankAccountCode
                ) {
                  if (this.personBankRefs[i].isEnable == 0) {
                    this.personBankRefs[i].isEnable = 1;
                  } else {
                    this.personBankRefs[i].isEnable = 0;
                  }
                } else {
                  this.personBankRefs[i].isEnable = 0;
                }
              }
            } else {
              this.$message.error(data.errorMsg);
            }
          });
        })
        .catch(() => { });
    },
  },
};
</script>
<style scoped>
.content div {
  box-sizing: border-box;
}
.contentList {
  display: flex;
}
.right {
  display: flex;
  flex: 1;
  justify-content: flex-end;
}
.red {
  color: #ff6600;
  font-weight: 600;
}
.title {
  font-size: 16px;
  font-weight: 600;
}
.m10 {
  padding-bottom: 10px;
}
.p10 {
  padding: 10px 0;
}
.day {
  height: 50px;
  line-height: 50px;
  background-color: rgba(228, 228, 228, 1);
  border-radius: 6px 6px 0 0;
  padding: 0 10px;
  box-sizing: border-box;
  position: relative;
  top: 10px;
}
</style>
